import {DateUtils} from '../../utils/Utils';
import IMSingleLinker from '../im/IMSingleLinker';

//单个聊天的链接
export default class IMOne2OneCommentLinker extends IMSingleLinker{
  constructor(props) {
    super(props);

    this._currentDatas = [];//存储当前视图在使用的数据
    this._dataKey = "msg_id";
    this._dataPage = 1;
  }

  getDatas() {
    return this._currentDatas;
  }

  init(params) {
    super.init(params);
    this._dataPage = 1;
    this._currentDatas = this._allDatas.slice(-this.PAGE_SIZE * this._dataPage);
    this._currentDatas.unshift({dataType:"top"});
  }

  _dealRequestData() {
    let page = 1;
    if(this._isLoadMore) {
      page = this._dataPage + 1;
      //是否本地有数据
      if(this._allDatas.length >= this.PAGE_SIZE * page) {
        this.requestFinish(this._allDatas.slice(-this.PAGE_SIZE * page), true);
        return;
      }
      //当前数据不满页
      else if(this._allDatas.length < this.PAGE_SIZE * this._dataPage) {
        page -= 1;
      }
    };
    this._sendAction(page);
  }

  _sendAction(page) {
    
  }

  _dealDatas(data) {
    super._dealDatas(data);
    if(this._isLoadMore) {
      this._dataPage += 1;
    }
    this._currentDatas = this._allDatas.slice(-this.PAGE_SIZE * this._dataPage);
    if(this._currentDatas.length < this.PAGE_SIZE * this._dataPage) {
      this._dataPage = parseInt(this._currentDatas.length / this.PAGE_SIZE);
      let less = this._currentDatas.length % this.PAGE_SIZE;
      if(less > 0) {
        this._dataPage += 1;
      }
    }
    this._currentDatas.unshift({dataType:"top"});
    console.log("_dealDatas", this._currentDatas, this._dataPage);
  }

  _sendUpdateCall(result, isLoadMore) {
    this._updateCall(this._currentDatas, result, isLoadMore);
  }
}
